<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="container-div">
    <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
        <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="pm:outsourceInfo:add">
            <i class="fa fa-plus"></i> 添加
        </a>
        <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
           shiro:hasPermission="pm:outsourceInfo:edit">
            <i class="fa fa-edit"></i> 修改
        </a>
        <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
           shiro:hasPermission="pm:outsourceInfo:remove">
            <i class="fa fa-remove"></i> 删除
        </a>-->

        <a class="btn btn-success" onclick="batchImport()">
            <i class="fa fa-cloud-upload"></i> 导入外包人员信息
        </a>
    </div>

    <div class="col-sm-12 select-table table-striped">
        <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">×
				</button>
				<h4 class="modal-title" id="myModalLabel">
					批量导入
				</h4>
			</div>
			<div class="modal-body">
				<input id="signFileUpload" name="signFileUpload" type="file" class="file" data-show-preview="false">
				<div class="text-center">
					<button type="button" id="batchSubmit" class="btn btn-primary">批量导入</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>

			</div>

		</div>
	</div>
</div>

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('pm:outsourceInfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('pm:outsourceInfo:remove')}]];
    var prefix = ctx + "pm/outsourceInfo";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "外包人员基本信息",
            search: false,
            showSearch: false,
            showColumns: false,
            showToggle: false,
            showExport: false,
            showRefresh: false,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号主键'
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'idCardNo',
                    title: '身份证号'
                },
                {
                    field: 'companyName',
                    title: '公司名称'
                },
                {
                    field: 'itemNumber',
                    title: '事项编号'
                },
                {
                    field: 'itemName',
                    title: '事项名称'
                },
                {
                    field: 'qualification',
                    title: '资质级别'
                },
                {
                    field: 'approachTime',
                    title: '进场时间',
                    formatter: function (value, row, index) {
                        var rowStr = "";
                        if (!!row.approachTime)
                            rowStr = '<span>' + row.approachTime.substr(0, 10) + '</span>';
                        return rowStr;
                    }
                },
                {
                    field: 'exitTime',
                    title: '退场时间',
                    formatter: function (value, row, index) {
                        var rowStr = "";
                        if (!!row.exitTime)
                            rowStr = '<span>' + row.exitTime.substr(0, 10) + '</span>';
                        return rowStr;
                    }
                }]
        };
        $.table.init(options);
    });

    function batchImport() {
        $('#signFileUpload').fileinput('clear');
        $('#myModal').modal('show');
    }

    //初始化fileinput控件（第一次初始化）
    function initFileInput(ctrlName, uploadUrl) {
        var control = $('#' + ctrlName);
        control.fileinput({
            language: 'zh',
            uploadUrl: uploadUrl, //上传的地址
            showPreview: false,
            allowedFileExtensions: ['xlsx', 'xls'],//接收的文件后缀
            minFileCount: 1,                                        // 最小上传数量
            maxFileCount: 1,                                        // 最大上传数量
            showUpload: false, //是否显示上传按钮
            showCaption: true,//是否显示标题
            showRemove: false,                                       // 显示移除按钮
            uploadClass: "btn btn-success",                        // 上传按钮样式
            browseClass: "btn btn-primary", //按钮样式
            autoReplace: true,
            //enctype: 'multipart/form-data',
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"

        })
    }

    initFileInput("signFileUpload", ctx + "pm/outsourceInfo/upload");

    $('#batchSubmit').on('click', function () {
        $.modal.confirm("你确定要上传 ?", function () {
            $('#signFileUpload').fileinput('upload');
        });

    })

    //  uploadAsync设置为true并且已触发批量上传时被触发
    $("#signFileUpload").on("fileuploaded", function (event, data, previewid, index) {
        var result = data.response;
        if (result.code == '0') {
            $.modal.msgSuccess("批量导入成功");
            $.table.refresh();
            $('#myModal').modal('hide');
        } else {
            layer.alert(result.msg, {
                icon: 0,
                area: ['60%', '90%'],
                title: "系统提示",
            }, function (index) {
                layer.close(index);
                $('#myModal').modal('hide');
            });
        }
        $.modal.closeLoading();
    });

    $("#signFileUpload").on('fileerror', function (event, data, msg) {
        $.modal.alertError("批量导入成功失败" + msg);
    });
</script>
</body>
</html>